<?php defined('_JEXEC') or die('Restricted access'); 

$ordering = ($this->lists['order'] == 'ordering');

JHTML::_('behavior.tooltip');
JHTML::stylesheet('base.css', JURI::root().'/components/com_simplelisting/css/');

?>

<form action="<?php echo $this->request_url; ?>" method="post" name="adminForm" >
<table>
    <tr>
        <td align="left" width="100%"><?php echo JText::_( 'LABEL_FIND_NAME' ).': '?>
        <input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area"onchange="document.adminForm.submit();" />
            <button onclick="this.form.submit();"><?php echo JText::_('BT_GO' ); ?></button>
            <button onclick="document.getElementById('search').value='';this.form.getElementById('filter_state').value='';this.form.submit();"><?php echo JText::_( 'BT_RESET' ); ?></button>
        </td>
        <td nowrap="nowrap">
        <?php echo JText::_('LABEL_FILTER').': '?>
        <?php echo $this->lists['state']; ?>
        </td>
</tr>
</table>
	<table class="adminlist" width="100%">
	<thead>
		<tr>
                    <th width="2%"><?php echo '#'; ?></th>
                    <th width="1%"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" /></th>
                    <th width="35%" class="title"><?php echo JHTML::_('grid.sort', JTEXT::_('LABEL_NAME'), 'a.name', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                    <th nowrap="nowrap" width="15%"><?php echo JHTML::_('grid.sort', JTEXT::_('LABEL_TYPE'), 't.name', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                    <th nowrap="nowrap" width="15%"><?php echo JHTML::_('grid.sort', JTEXT::_('LABEL_CATEGORY'), 'ca.name', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                    <th width="15%"><?php echo JHTML::_('grid.sort', JTEXT::_('LABEL_CONTACT_NAME'), 'a.create_by', $this->lists['order_Dir'] , $this->lists['order']  ) ?></th>

                    <th width="5%" nowrap="nowrap" align="center">
                    <?php echo JHTML::_('grid.sort', 'ORDER', 'ordering', $this->lists['order_Dir'], $this->lists['order'] ); ?>
                    <?php if ($ordering) echo JHTML::_('grid.order',  $this->items); ?>
                    </th>

                    <th width="2%"><?php echo JHTML::_('grid.sort',JTEXT::_('LABEL_PUBLISHED'), 'a.published', $this->lists['order_Dir'], $this->lists['order'] ); ?></th>
                    <th width="5%"><?php echo JHTML::_('grid.sort', JTEXT::_('LABEL_POSTED_DATE'), 'a.date_created', $this->lists['order_Dir'] , $this->lists['order']  ) ?></th>
                    <th width="2%"><?php echo JTEXT::_('LABEL_ID'); ?></th>
                </tr>
	</thead>	
    <tbody>
	<?php
	$k = 0;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)
	{
		$row = &$this->items[$i];

		$link 	= JRoute::_( 'index.php?option=com_simplelisting&controller=listings&task=edit&cid[]='. $row->id );
                $checked = JHTML::_('grid.id', $i, $row->id );
		//$checked 	= JHTML::_('grid.checkedout',   $row, $i );
		$published  = JHTML::_('grid.published', $row, $i );
	
		?>
		<tr class="<?php echo "row$k"; ?>">
                    <td><?php echo $this->pagination->getRowOffset( $i ); ?></td>
                    <td><?php echo $checked; ?></td>
                    <td><a href="<?php echo $link; ?>" title="<?php echo JText::_( 'TT_EDIT_LISTING' ); ?>"><?php echo $row->name; ?></a></td>
                    <td align="center"><?php echo $this->escape( $row->type ); ?></td>
                    <td align="center"><?php echo $this->escape( $row->category); ?></td>
                    <td align="center">
                        <?php if ( $this->user->authorize( 'com_users', 'manage' ) ): ?>
                             <a href="<?php echo JRoute::_( 'index.php?option=com_users&task=edit&cid[]='.$this->escape( $row->userid))  ?>" title="<?php echo JText::_( 'TT_EDIT_USER' ) ?> "><?php echo $this->escape( $row->username) ?></a>
                        <?php else : echo $row->create_by; ?>
                        <?php endif ?>
                    </td>

                    <td class="order" nowrap="nowrap">
                            <span><?php echo $this->pagination->orderUpIcon( $i, ($row->position == @$rows[$i-1]->position), 'orderup', 'Move Up', $row->ordering ); ?></span>
                            <span><?php echo $this->pagination->orderDownIcon( $i, $n, ($row->position == @$rows[$i+1]->position),'orderdown', 'Move Down', $row->ordering ); ?></span>

                            <?php $disabled = $ordering ?  '' : 'disabled="disabled"'; ?>

                            <input type="text" name="order[]" size="5" value="<?php echo $row->ordering; ?>" class="text_area" style="text-align: center" />
                    </td>
                    <td align="center"><?php echo $published; ?></td>
                    <td align="center"><?php echo JHTML::_('date',  $row->date_created, JText::_('DATE_FORMAT_LC4') ); ?></td>
                    <td align="center"><?php echo $this->escape( $row->id); ?></td>
		</tr>
                    <?php
                    $k = 1 - $k;
                    }
                    ?>
    </tbody>
        <tfoot>
		<td colspan="10">
			<?php echo $this->pagination->getListFooter(); ?>
		</td>
	</tfoot>
	</table>
<input type="hidden" name="option" value="com_simplelisting" />
<input type="hidden" name="view" value="listings" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
<input type="hidden" name="filter_order_Dir" value="" />

</form>
